package com.hmdp.config;

import com.hmdp.utils.LoginInterceptor;
import com.hmdp.utils.RefreshInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @className: com.hmdp.config-> Mvc
 * @description: 这个是springMVC配置类 在这里添加了拦截器
 * @author: chenhs
 * @createDate: 2024-03-02 23:00
 * @version: 1.0
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        WebMvcConfigurer.super.addInterceptors(registry);
    /****
     *多个拦截器执行顺序配置规则
     * 默认情况下根据拦截器被添加的顺序执行
     * 可可以根据设置 来指定执行顺序， .order()   数字越小越优先执行。
     * 配置执行顺序高于拦截器被添加顺序
     **/
        registry.addInterceptor(new RefreshInterceptor(stringRedisTemplate)).order(0);
//        添加拦截器
        registry.addInterceptor(new LoginInterceptor())
//                放行不拦截路径
                .excludePathPatterns(
                        "/shop/**",
                        "/voucher/**",
                        "/shop-type/**",
                        "/upload/**",
                        "/blog/hot",
                        "/user/code",
                        "/user/login"
                ).order(1);
    }
}
